<?php

namespace app\appv110\controller;

use app\appv110\controller\CommonController;
use think\Validate;
use think\Db;
use app\util\Utils;
use app\appv110\model\StaffNote;
use app\appv110\model\StaffNoteBack;
use app\appv110\model\StaffBindStore;
use app\appv110\model\Staff;

class StaffController extends CommonController {
    /*
     * code列表
     */

    public function code() {
        /*
         * 0  成功
         * 1  参数错误
         * 2  验证失败
         * 40000  备注失败
         * 40001  没有发现该备注
         * 40002  修改备注失败
         * 40003  请先绑店再打卡
         * 40004  您已经在其他店打卡了
         * 40005  没有发现打卡信息
         * 40006  请在工作时间内打卡
         * 
         */
    }

    /*
     * 给用户添加备注
     * author xfwed
     * date 2019.12.04
     */

    public function addStaffNote() {
        $rule = [
            'staff_id' => 'require',
            'ctm_id' => 'require',
//            'note' => 'require',
//            'name' => 'require',
        ];
        $msg = [
            'staff_id.require' => '美容师id必须',
            'ctm_id.require' => '用户id必须',
//            'note.require' => '备注必须',
//            'name.require' => '备注名字必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $staff_id = $all['staff_id']; //美容师id
        $ctm_id = $all['ctm_id']; //用户id
        $note = input('param.note'); //备注
        $name = input('param.name'); //备注姓名
        $row = StaffNote::where('staff_id', $staff_id)
                ->where('ctm_id', $ctm_id)
                ->find();
        Db::startTrans();
        $data['staff_id'] = $staff_id;
        $data['ctm_id'] = $ctm_id;
        $data['note'] = $note;
        $data['name'] = $name;
        $data['add_time'] = date('Y-m-d H:i:s', time());
        if ($row) {
            if ($name) {
                $save = StaffNote::where('staff_id', $staff_id)
                        ->where('ctm_id', $ctm_id)
                        ->update(['name' => $name, 'note' => $note, 'add_time' => date('Y-m-d H:i:s', time())]);
            } else {
                $save = TRUE;
            }
        } else {
            $save = TRUE;
            $insert = StaffNote::insert($data);
        }
        $insert = StaffNoteBack::insert($data);
        if ($save && $insert) {
            Db::commit();
            return Utils::ajaxReturn(0, '备注成功', null);
        } else {
            Db::rollback();
            return Utils::ajaxReturn(40000, '备注失败', null);
        }
    }

    /*
     * 修改备注
     * author xfwed
     * date 2019.12.04
     */

    public function saveStaffNote() {
        $rule = [
            'id' => 'require',
        ];
        $msg = [
            'id.require' => 'id必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $id = $all['id']; //美容师id
        $note = input('param.note'); //备注
        $name = input('param.name'); //备注姓名
        $row = StaffNoteBack::where('id', $id)->find();
        Db::startTrans();
        if ($name) {
            $save = StaffNote::where('staff_id', $row['staff_id'])
                    ->where('ctm_id', $row['ctm_id'])
                    ->update(['name' => $name]);
        }
        $saveRow = StaffNoteBack::where('id', $id)->update(['name' => $name, 'note' => $note]);

        if ($saveRow) {
            Db::commit();
            return Utils::ajaxReturn(0, '修改备注成功', null);
        } else {
            Db::rollback();
            return Utils::ajaxReturn(40002, '修改备注失败', null);
        }
    }

    /*
     * 删除备注
     * author xfwed
     * date 2019.12.04
     */

    public function delStaffNote() {
        $rule = [
            'id' => 'require',
        ];
        $msg = [
            'id.require' => 'id必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $id = $all['id']; //美容师id
        $row = StaffNoteBack::where('id', $id)->find();
        $noteCount = StaffNoteBack::where('staff_id', $row['staff_id'])
                ->where('ctm_id', $row['ctm_id'])
                ->count();
        if (empty($row)) {
            return Utils::ajaxReturn(40001, '没有发现该备注', null);
        } else {
            if ($noteCount == 1) {
                StaffNote::where('staff_id', $row['staff_id'])
                        ->where('ctm_id', $row['ctm_id'])
                        ->delete();
            }
            $saveRow = StaffNoteBack::where('id', $id)->delete();
        }

        return Utils::ajaxReturn(0, '删除备注成功', null);
    }

    /*
     * 备注记录
     * author xfwed
     * date 2019.12.04
     */

    public function staffNoteList() {
        $rule = [
            'staff_id' => 'require',
            'ctm_id' => 'require',
            'perPage' => 'integer|egt:1',
            'page' => 'integer|egt:1',
        ];
        $msg = [
            'ctm_id.require' => '用户id必须',
            'staff_id.require' => '美容师id必须',
            'perPage.integer' => '每页数量为数字',
            'perPage.egt' => '每页数量最小为1',
            'page.integer' => '当前页数为数字',
            'page.egt' => '当前页数最小为1',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $ctm_id = $all['ctm_id'];
        $staff_id = $all['staff_id'];
        $perPage = isset($all['perPage']) ? $all['perPage'] : 10;
        $page = isset($all['page']) ? $all['page'] : 0;
        if ($page == 0) {
            $page = 1;
        }

        $offset = ($page - 1) * $perPage;

        $list = StaffNoteBack::where('staff_id', $staff_id)
                ->where('ctm_id', $ctm_id)
                ->limit($offset, $perPage)
                ->field('id,note,name,add_time')
                ->select();
        return Utils::ajaxReturn(0, '查询成功', $list);
    }

    /*
     * 备注详情
     * author xfwed
     * date 2019.12.04
     */

    public function staffNoteInfo() {
        $rule = [
            'id' => 'require',
        ];
        $msg = [
            'id.require' => 'id必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $id = $all['id'];
        $row = StaffNoteBack::where('id', $id)->find();
        if (empty($row)) {
            return Utils::ajaxReturn(40001, '没有发现该备注', null);
        } else {
            return Utils::ajaxReturn(0, '查询成功', $row);
        }
    }

    /*
     * 美容师打卡/离店
     * author xfwed
     * date 2020.11.19
     */

    public function staffsign() {
        $lockFile = ROOT_PATH . 'application/util/lock_staffsign.txt';
        $f = fopen($lockFile, 'r');
        if (flock($f, LOCK_EX)) {
            $rule = [
                'staff_id' => 'require',
                'store_id' => 'require',
                'status' => 'require',
            ];
            $msg = [
                'staff_id.require' => 'id必须',
                'store_id.require' => 'id必须',
                'status.require' => 'id必须',
            ];

            $all = input('param.');

            $validate = new Validate($rule, $msg);
            if (!$validate->check($all)) {
                $error = $validate->getError();

                return Utils::ajaxReturn(1, $error, null);
            }

            $staff_id = $all['staff_id'];
            $store_id = $all['store_id'];
            $status = $all['status']; //1打卡 2离店
            $type = input('param.type');//1手动操作 2自动操作	
            if ($status == 1) {
                $bindRow = StaffBindStore::where('staff_id', $staff_id)
                        ->where('store_id', $store_id)
                        ->find();
                if (empty($bindRow)) {
                    return Utils::ajaxReturn(40003, '请先绑店再打卡', null);
                }

                //判断是否在其他店打卡
                $signRow = Db::name('staff_sign')
                        ->where('staff_id', $staff_id)
                        ->where('status', 1)
                        ->find();
                if ($signRow) {
                    return Utils::ajaxReturn(40004, '您已经在其他店打卡了', null);
                }

                //判断是否在工作时间内9:00-21:00  改成 7-24
                $h = date('G', time());
                if ($h < 7 || $h > 23) {
                    return Utils::ajaxReturn(40006, '请在工作时间内打卡', null);
                }

                $result = Db::name('staff_sign')
                        ->insert([
                    'staff_id' => $staff_id,
                    'store_id' => $store_id,
                    'add_time' => date('Y-m-d H:i:s', time()),
                    'status' => 1,
                    'type' => $type,
                ]);
                if ($result) {
                    //是否可以插入满勤分
                    Staff::addStaffScore($staff_id);
                    return Utils::ajaxReturn(0, '打卡成功', NULL);
                } else {
                    return Utils::ajaxReturn(3, '打卡失败', NULL);
                }
            } else {
                //判断是否打卡
                $signRow = Db::name('staff_sign')
                        ->where('staff_id', $staff_id)
                        ->where('store_id', $store_id)
                        ->where('status', 1)
                        ->find();
                if (empty($signRow)) {
                    return Utils::ajaxReturn(40005, '没有发现打卡信息', null);
                }

                $result = Db::name('staff_sign')
                        ->where('staff_id', $staff_id)
                        ->where('store_id', $store_id)
                        ->where('status', 1)
                        ->update(['status' => 2, 'leave_time' => date('Y-m-d H:i:s', time())]);
                if ($result) {
                    return Utils::ajaxReturn(0, '离店成功', NULL);
                } else {
                    return Utils::ajaxReturn(3, '离店失败', NULL);
                }
            }
        }
        fclose($f);
    }

    /*
     * 美容师扫码入团
     * author xfwed 
     * date 2021.01.20
     */

    public function addteamStaff() {
        $rule = [
            'team_id' => 'require',
            'staff_id' => 'require',
        ];
        $msg = [
            'team_id.require' => '团队id必须',
            'staff_id.require' => '美容师id必须',
        ];
        $all = input('post.');
        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();
            return Utils::ajaxReturn(1, $error, null);
        }
        $team_id = input('param.team_id');
        $staff_id = input('param.staff_id');
        $teamRow = Db::name('staff_team')->where('id', $team_id)->where('status', 1)->find();
        $staffRow = Db::name('staff')->where('id', $staff_id)->find();
        if (empty($teamRow)) {
            return Utils::ajaxReturn(3, '二维码无效', null);
        }
        //授权服务店的美容师不能进品牌连锁店的团
        if($staffRow['type'] == 2){
            $store_ids = Db::name('staff_team_store')
                    ->where('team_id',$team_id)
                    ->where('status',1)
                    ->column('store_id');
            $storeRow = Db::name('store')
                    ->where('id','in',$store_ids)
                    ->where('type',1)
                    ->find();
            if($storeRow){
                 return Utils::ajaxReturn(3, '请扫授权服务店的团队码', null);
            }
        }
        $std = Db::name('staff_team_details')->where('staff_id', $staff_id)
                ->where('status', 'in', '1,2')
                ->find();
        if ($std) {
            return Utils::ajaxReturn(3, '该美容师已经绑定团队', null);
        }
        if ($staffRow['staff_rank'] == 5 && $teamRow['captain_id'] != $staff_id) {
            return Utils::ajaxReturn(3, '请扫描本团队二维码', null);
        }

        $max_members_num = Db::name('staff_team')->where('id', $team_id)->value('max_members_num');
        $stdCount = Db::name('staff_team_details')->where('team_id', $team_id)
                ->where('status', 'in', '1,2')
                ->count();
        if ($stdCount >= $max_members_num) {
            return Utils::ajaxReturn(3, '该团队已经满了', null);
        }

        Db::startTrans();
        $std3 = Db::name('staff_team_details')->where('staff_id', $staff_id)
                ->where('status', 3)
                ->find();
        if ($std3) {
            $add = Db::name('staff_team_details')->where('id', $std3['id'])
                    ->update([
                'team_id' => $all['team_id'],
                'staff_id' => $all['staff_id'],
                'status' => 1,
                'add_time' => date('Y-m-d H:i:s')]);
        } else {
            //添加成员
            $data['team_id'] = $all['team_id'];
            $data['staff_id'] = $all['staff_id'];
            $data['add_time'] = date('Y-m-d H:i:s');
            $add = Db::name('staff_team_details')->insertGetId($data);
        }

        //添加团队成员进出记录
        $logsdata['staff_id'] = $all['staff_id'];
        $logsdata['team_id'] = $all['team_id'];
        $logsdata['status'] = 1;
        $logsdata['note'] = '美容师自己扫码入团';
        $logsdata['add_time'] = date('Y-m-d H:i:s');
        $lodsResult = Db::name('staff_team_logs')->insert($logsdata);
        //美容师和店铺的绑定关系
        $storeIds = Db::name('staff_team_store')->where('team_id', $all['team_id'])
                ->where('status', 1)
                ->column('store_id');
        $staffbind_arr = [];
        for ($j = 0; $j < count($storeIds); $j++) {
            $staffbind_arr[] = [
                'staff_id' => $all['staff_id'],
                'store_id' => $storeIds[$j],
                'add_time' => date('Y-m-d H:i:s'),
            ];
        }
        $sbsResult = Db::name('staff_bind_store')->insertAll($staffbind_arr);

        if ($add && $lodsResult && $sbsResult) {
            Db::commit();
            return Utils::ajaxReturn(0, '入团成功', null);
        } else {
            Db::rollback();
            return Utils::ajaxReturn(3, '入团失败', null);
        }
    }

    /*
     * 店铺邀请入团二维码
     * author xfwed 
     * date 2021.01.20
     */

    public function storeTeamQrcode() {
        $rule = [
            'store_id' => 'require',
        ];
        $msg = [
            'store_id.require' => '店铺id必须',
        ];
        $all = input('post.');
        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();
            return Utils::ajaxReturn(1, $error, null);
        }
        $store_id = input('param.store_id');
        $team_id = Db::name('staff_team_store')
                ->where('store_id', $store_id)
                ->where('status', 1)
                ->value('team_id');
        if (empty($team_id)) {
            return Utils::ajaxReturn(3000, '暂没有美容师团队为您服务，请联系客服400-801-3680', null);
        }
        $teamRow = Db::name('staff_team')
                ->where('id', $team_id)
                ->field('status,qrcode')
                ->find();
        if ($teamRow['status'] == 2) {
            return Utils::ajaxReturn(3, '您所在的团已经解散', null);
        }
        return Utils::ajaxReturn(0, '查询成功', $teamRow['qrcode']);
    }

    /*
     * 店铺补贴活动
     * author xfwed
     * date 2021.06.22
     */

    public function storeSubsidySetup() {
        $rule = [
            'store_id' => 'require',
            'perPage' => 'integer|egt:1',
            'page' => 'integer|egt:1',
        ];
        $msg = [
            'store_id.require' => '店铺id必须',
            'perPage.integer' => '每页数量为数字',
            'perPage.egt' => '每页数量最小为1',
            'page.integer' => '当前页数为数字',
            'page.egt' => '当前页数最小为1',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $store_id = $all['store_id'];
        $perPage = isset($all['perPage']) ? $all['perPage'] : 10;
        $page = isset($all['page']) ? $all['page'] : 0;
        if ($page == 0) {
            $page = 1;
        }

        $offset = ($page - 1) * $perPage;

        $list = Db::name('subsidy_setup')
                ->where('store_id', $store_id)
                ->limit($offset, $perPage)
                ->field('id,money,start_time,end_time,why,status')
                ->order('add_time desc')
                ->select();
        foreach ($list as $k => $v) {
            $id = $v['id'];
            $peopleNum = Db::name('staff_flow_new')
                    ->where('subsidy_setup_id', $id)
                    ->where('status', '<>', 3)
                    ->group('staff_id')
                    ->count();
            $list[$k]['peopleNum'] = $peopleNum; //人数
            $orderNum = Db::name('staff_flow_new')
                    ->where('subsidy_setup_id', $id)
                    ->where('status', '<>', 3)
                    ->count();
            $list[$k]['orderNum'] = $orderNum; //单数
        }
        $data['list'] = $list;
        //已补金额(元)   已补美容师(人)   已补订单数(个)    剩余金额
        $money = Db::name('subsidy_setup')
                ->where('store_id', $store_id)
                ->sum('money');
        $data['money'] = $money;
        $ids = Db::name('subsidy_setup')
                ->where('store_id', $store_id)
                ->column('id');
        if ($ids) {
            $peopleNum = Db::name('staff_flow_new')
                    ->where('subsidy_setup_id', 'in', $ids)
                    ->where('status', '<>', 3)
                    ->group('staff_id')
                    ->count();
            $orderNum = Db::name('staff_flow_new')
                    ->where('subsidy_setup_id', 'in', $ids)
                    ->where('status', '<>', 3)
                    ->count();
        } else {
            $peopleNum = 0;
            $orderNum = 0;
        }
        $data['peopleNum'] = $peopleNum;
        $data['orderNum'] = $orderNum;
        $subsidyMoney = Db::name('store')
                ->where('id', $store_id)
                ->value('subsidy_money');
        $data['subsidyMoney'] = $subsidyMoney;

        return Utils::ajaxReturn(0, '查询成功', $data);
    }

    /*
     * 本店已补贴美容师
     * author xfwed
     * date 2021.06.22
     */

    public function storeSubsidyStaffList() {
        $rule = [
            'store_id' => 'require',
        ];
        $msg = [
            'store_id.require' => '店铺id必须',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $store_id = $all['store_id'];

        $ids = Db::name('subsidy_setup')
                ->where('store_id', $store_id)
                ->column('id');

        $staff_ids = Db::name('staff_flow_new')
                ->where('subsidy_setup_id', 'in', $ids)
                ->where('status', '<>', 3)
                ->group('staff_id')
                ->column('staff_id');
        $list = Db::name('staff')
                ->where('id', 'in', $staff_ids)
                ->field('id,staff_name')
                ->select();

        return Utils::ajaxReturn(0, '查询成功', $list);
    }

    /*
     * 补贴记录
     * author xfwed
     * date 2021.06.22
     */

    public function storeSubsidyList() {
        $rule = [
            'id' => 'require',
            'dateType' => 'require',
            'perPage' => 'integer|egt:1',
            'page' => 'integer|egt:1',
        ];
        $msg = [
            'id.require' => '活动id必须',
            'dateType.require' => '日期类型必须',
            'perPage.integer' => '每页数量为数字',
            'perPage.egt' => '每页数量最小为1',
            'page.integer' => '当前页数为数字',
            'page.egt' => '当前页数最小为1',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $id = $all['id'];
        $perPage = isset($all['perPage']) ? $all['perPage'] : 10;
        $page = isset($all['page']) ? $all['page'] : 0;
        if ($page == 0) {
            $page = 1;
        }

        $offset = ($page - 1) * $perPage;

        $dateType = $all['dateType']; //0.本日 1.本周 2.本月 3.全部 4.自定义
        $startTime = input('param.startDate');
        $endTime = input('param.endDate');
        $staff_id = input('param.staff_id');
        //php获取今日开始时间戳和结束时间戳
        $beginToday = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
        $endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
        //php获取本周起始时间
        $beginWeek = mktime(0, 0, 0, date("m"), date("d") - date("w") + 1, date("Y"));
        $endWeek = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));
        //$beginWeek = time()- 60*60*24*7;
        //$endWeek = time();
        //php获取本月起始时间戳和结束时间戳
        $beginThismonth = mktime(0, 0, 0, date('m'), 1, date('Y'));
        $endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
        if ($dateType == 0) {
            $where['add_time'] = ['between', [date('Y-m-d H:i:s', $beginToday), date('Y-m-d H:i:s', $endToday)]];
            $where1['sfl.add_time'] = ['between', [date('Y-m-d H:i:s', $beginToday), date('Y-m-d H:i:s', $endToday)]];
        } elseif ($dateType == 1) {
            $where['add_time'] = ['between', [date('Y-m-d H:i:s', $beginWeek), date('Y-m-d H:i:s', $endWeek)]];
            $where1['sfl.add_time'] = ['between', [date('Y-m-d H:i:s', $beginWeek), date('Y-m-d H:i:s', $endWeek)]];
        } elseif ($dateType == 2) {
            $where['add_time'] = ['between', [date('Y-m-d H:i:s', $beginThismonth), date('Y-m-d H:i:s', $endThismonth)]];
            $where1['sfl.add_time'] = ['between', [date('Y-m-d H:i:s', $beginThismonth), date('Y-m-d H:i:s', $endThismonth)]];
        } elseif ($dateType == 4) {
            $where['add_time'] = ['between', [$startTime, date('Y-m-d H:i:s', strtotime($endTime) + 24 * 60 * 60)]];
            $where1['sfl.add_time'] = ['between', [$startTime, date('Y-m-d H:i:s', strtotime($endTime) + 24 * 60 * 60)]];
        }

        if ($staff_id) {
            $where['staff_id'] = $staff_id;
            $where1['sfl.staff_id'] = $staff_id;
        }
        $where = isset($where) ? $where : [];
        $where1 = isset($where1) ? $where1 : [];
        $peopleNum = Db::name('staff_flow_new')
                ->where('subsidy_setup_id', $id)
                ->where('status', '<>', 3)
                ->where($where)
                ->group('staff_id')
                ->count();
        $data['peopleNum'] = $peopleNum; //人数
        $orderNum = Db::name('staff_flow_new')
                ->where('subsidy_setup_id', $id)
                ->where('status', '<>', 3)
                ->where($where)
                ->count();
        $data['orderNum'] = $orderNum; //单数

        $money = Db::name('staff_flow_new')
                ->where('subsidy_setup_id', $id)
                ->where('status', '<>', 3)
                ->where($where)
                ->sum('subsidy_money');
        $data['money'] = $money; //金额

        $activity = Db::name('subsidy_setup')
                ->where('id', $id)
                ->field('id,money,min_service,min_money,max_service,max_money')
                ->find();
        $data['activity'] = $activity;
        $list = Db::name('staff_flow_new')
                ->alias('sfl')
                ->join('staff s', 's.id = sfl.staff_id', 'left')
                ->join('yuyue y', 'y.id = sfl.order_id', 'left')
                ->join('order o', 'o.id = y.order_id', 'left')
                ->where('subsidy_setup_id', $id)
                ->where($where1)
                ->field('sfl.id,sfl.order_id,sfl.item_name,sfl.subsidy_money,sfl.subsidy_day_index,sfl.status,sfl.add_time,s.staff_name,s.staff_photo,o.first_exemption')
                ->limit($offset, $perPage)
                ->order('id desc')
                ->select();
        $data['list'] = $list;
        return Utils::ajaxReturn(0, '查询成功', $data);
    }

    /*
     * 补贴充值记录
     * author xfwed
     * date 2021.06.29
     */

    public function storeSubsidyRecharge() {
        $rule = [
            'store_id' => 'require',
            'perPage' => 'integer|egt:1',
            'page' => 'integer|egt:1',
        ];
        $msg = [
            'store_id.require' => '店铺id必须',
            'perPage.integer' => '每页数量为数字',
            'perPage.egt' => '每页数量最小为1',
            'page.integer' => '当前页数为数字',
            'page.egt' => '当前页数最小为1',
        ];

        $all = input('param.');

        $validate = new Validate($rule, $msg);
        if (!$validate->check($all)) {
            $error = $validate->getError();

            return Utils::ajaxReturn(1, $error, null);
        }

        $store_id = $all['store_id'];
        $perPage = isset($all['perPage']) ? $all['perPage'] : 10;
        $page = isset($all['page']) ? $all['page'] : 0;
        if ($page == 0) {
            $page = 1;
        }

        $offset = ($page - 1) * $perPage;



        $money = Db::name('subsidy_recharge')
                ->where('store_id', $store_id)
                ->sum('money');
        $data['money'] = $money; //金额

        $list = Db::name('subsidy_recharge')
                ->where('store_id', $store_id)
                ->limit($offset, $perPage)
                ->order('id desc')
                ->select();
        $data['list'] = $list;
        return Utils::ajaxReturn(0, '查询成功', $data);
    }

}
